const Router = require("koa-router");
const R = require("../app/R");

const categoryDao = require("../dao/CategoryDao");

const CategoryRouter = new Router({ prefix: "/category" });

CategoryRouter.get("/list", async (ctx, next) => {
  const result = await categoryDao.list();
  ctx.body = new R().setResult({
    CategoryList: result,
  });
});

CategoryRouter.post("/getOne", async (ctx, next) => {
  const data = ctx.request.body;
  const result = await categoryDao.getOneById(data.Id);
  ctx.body = new R().setResult({
    Category: result,
  });
});

module.exports = CategoryRouter;
